<template>
    <el-main>

      <el-form :inline="true" :model="queryForm" class="demo-form-inline">
        <el-form-item label="审批人">
          <el-input v-model="queryForm.name" placeholder="审批人"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>


      <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange">
        <el-table-column
          type="selection"
          width="55">
        </el-table-column>
        <el-table-column
          label="id"
          width="120">
          <template slot-scope="scope">{{ scope.row.id }}</template>
        </el-table-column>
        <el-table-column
          prop="name"
          label="姓名"
          width="120">
        </el-table-column>
        <el-table-column
          prop="price"
          label="价格"
          show-overflow-tooltip>
        </el-table-column>

        <el-table-column
          prop="imge_url"
          label="图片"
          show-overflow-tooltip>
        </el-table-column>

        <el-table-column
          prop="upper_Status"
          label="上架状态"
          show-overflow-tooltip>
        </el-table-column>

        <el-table-column
          prop="factory_date"
          label="日期"
          show-overflow-tooltip>
        </el-table-column>

      </el-table>
      <div style="margin-top: 20px">
        <el-button @click="toggleSelection([tableData[1], tableData[2]])">切换第二、第三行的选中状态</el-button>
        <el-button @click="toggleSelection()">取消选择</el-button>
      </div>

      <el-pagination
        background
        layout="prev, pager, next"
        :current-page="queryForm.pageNo"
        :page-size="queryForm.pageSize"
        @current-change="changePage"
        :total="total">
      </el-pagination>


    </el-main>
</template>

<script>
  const  axios = require('axios');
    export default {
        data() {
            return {
                tableData: [{}],
                queryForm:{
                    pageNo:1,
                    pageSize:2
                },
                total:0,
                multipleSelection: []
            }
        },


        methods: {
            toggleSelection(rows) {
                if (rows) {
                    rows.forEach(row => {
                        this.$refs.multipleTable.toggleRowSelection(row);
                    });
                } else {
                    this.$refs.multipleTable.clearSelection();
                }
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },

            onSubmit(){
                this.getList();
            },

            getList(){
                let self = this
                axios({
                    method:'get',
                    url:'http://localhost:888/list',
                    params:this.queryForm

                }).then(function (obj) {
                    console.log(obj.data)
                    self.tableData=obj.data.list;
                    self.total=obj.data.total;
                })
            },
            changePage(pageNo){
                this.queryForm.pageNo=pageNo
                this.getList();
            }
        },
        created() {
            this.getList();
        }
    }
</script>

<style scoped>

</style>
